<template>
	<view class="page">
		<view class="titbg">
			<view class="ludan" @click="goLuDan">
				<image src="../../static/pagesA-img/images/ludan.png" class="ludan-img"></image>
				<view class="">手工录单</view>
			</view>
		</view>
		<!-- 用户信息(头像/昵称) -->
		<view class="zindex-o">
			<view class="user-info">
				<view class="header-img">
					<!-- #ifdef MP-WEIXIN -->
					<open-data  class="user-img" type="userAvatarUrl"></open-data>
					<!-- #endif -->
					<!-- #ifdef H5 -->
					<image :src="userdata.avatar"  class="user-img"></image>
					<!-- #endif -->
					
				</view>
				<view class="">
					<view class="user-name">
					<!-- #ifdef MP-WEIXIN -->
					<open-data type="userNickName"></open-data>
					<!-- #endif -->
					<!-- #ifdef H5 -->
					{{userdata.nickname}}
					<!-- #endif -->
					</view>
				</view>
				
			</view>
			<!-- 店铺/商品	笔记	元宝 -->
			<view class="header-box">
				<view class="header-box-tit">
					<view class="box-2">
						<view class="text" @click="goGoods">
							<text>商品/店铺</text>
							<view class="">{{goods_count}}</view>
						</view>
						<view class="text" @click="goNote">
							<text>笔记</text>
							<view class="">{{note_count_all}}</view>
						</view>
						<view class="text"  @click="goGold">
							<text>元宝</text>
							<view class="">{{user_info.virtual_money || '0'}}</view>
						</view>
					</view>
				</view>
			</view>
			<!-- 店铺/商品	笔记	元宝 end -->
			<view class="list-1" @click="goBonus">
				<view class="jiangli">奖励明细</view>
				<image lazy-load="true"  src="../../static/images/jiantou1.png" class="jiantou"></image>
			</view>
			<view class="list-1" @click="gobaobei" v-if="user_info.is_receiver || user_info.is_reportor">
				<view class="jiangli">引流报备</view>
				<image lazy-load="true"  src="../../static/images/jiantou1.png" class="jiantou"></image>
			</view>
			<view class="list-1" @click="goInvite">
				<view class="jiangli">关联的人</view>
				<image lazy-load="true"  src="../../static/images/jiantou1.png" class="jiantou"></image>
			</view>
			<!-- 我的订单 -->
			<view class="list-2" >
				<view class="list-2-tit" @click="goOrder(1)">
					<view class="jiangli">我的订单</view>
					<view class="all-order">
						<view class="all-text">全部订单</view>
						<image lazy-load="true"  src="../../static/images/jiantou1.png" class="jiantou1"></image>
					</view>
				</view>
				<view class="menu-box">
					<view class="menu-item" @click="goOrder(1)">
						<image lazy-load="true"  src="../../static/images/main-1.png" class="main1"></image>
						<view class="">待付款</view>
					</view>
					<view class="menu-item" @click="goOrder(2)">
						<image lazy-load="true"  src="../../static/images/main-2.png" class="main2"></image>
						<view class="">待发货</view>
					</view>
					<view class="menu-item" @click="goOrder(3)">
						<image lazy-load="true"  src="../../static/images/main-3.png" class="main3"></image>
						<view class="">待收货</view>
					</view>
					<view class="menu-item" @click="goOrder(5)">
						<image lazy-load="true"  src="../../static/images/main-4.png" class="main4"></image>
						<view class="">已完成</view>
					</view>
				</view>
			</view>
			<!-- 功能列表 -->
			<view class="list-3">
				<view class="item item1" @click="chooseAddr">
					<view class="img">
						<image lazy-load="true"  src="../../static/images/main-5.png" class="main5"></image>
					</view>
					<view class="">收货地址</view>
				</view>
				<view class="item item2" @click="goNew()">
					<view class="img">
						<image lazy-load="true"  src="../../static/images/main-6.png" mode="widthFix" class="main6"></image>
					</view>
					<view class="">消息</view>
				</view>
				<view class="item item3">
					<!-- #ifdef MP-WEIXIN -->
					<button  open-type="feedback">
						<view class="img">
							<image lazy-load="true"  src="../../static/images/main-7.png" mode="widthFix" class="main7"></image>
						</view>
						<view class="">意见反馈</view>
					</button>
					<!-- #endif -->
					<!-- #ifdef H5 -->
					<view class="img" @click="goFeedBack">
						<image lazy-load="true"  src="../../static/images/main-7.png" mode="widthFix" class="main7"></image>
					</view>
					<view class="">意见反馈</view>
					<!-- #endif -->
				</view>
				<view class="item item4" @click="goAboutUs">
					<view class="img">
						<image lazy-load="true"  src="../../static/images/main-8.png" mode="widthFix" class="main8"></image>
					</view>
					<view class="">关于我们</view>
				</view>
				<view class="item item5" @click="goHelp">
					<view class="img">
						<image lazy-load="true"  src="../../static/images/main-9.png" mode="widthFix" class="main9"></image>
					</view>
					<view class="">帮助</view>
				
				</view>
				<view class="item item6" @click="log_out" >
					<view class="img">
						<image lazy-load="true"  src="../../static/images/main-10.png" mode="widthFix" class="main10"></image>
					</view>
					<view class="">退出账号</view>
				</view>
			</view>
		</view>
		<!-- <tabBar active_num="5"></tabBar> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user_info:{},
				is_load:false,
				goods_count:0,
				note_count_all:0,
				stauts_code:0,
				userdata:{}
			}
		},
		onLoad() {
			if(uni.getStorageSync('userdata')){
				this.userdata = JSON.parse(uni.getStorageSync('userdata'));
			}			
		},
		onShow(){
			var self = this;
			self.$request.request({
				url:'/user/info',
				success:function(res){
					self.stauts_code = res.code;
					if(res.code==200){
						self.is_load = true;
						var  y = res.result;
						y.rebate_count = self.$money(y.rebate_count);
						self.user_info = y;
						console.log(y)
						self.goods_count = parseInt(y.goods_follow_count) + parseInt(y.store_follow_count);
						self.note_count_all = parseInt(y.note_count) + parseInt(y.note_follow_count);
					}else{
						
					}
				}
			});
			// #ifdef H5
			let share_time_line={
				title:self.$request.h5_share_name, // 分享标题
				link: self.$request.h5_share_url+'?page=index', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
				imgUrl: self.$request.h5_img_url+'/static/images/logo.png', // 分享图标
			}
			let share_app_message={
				title: self.$request.h5_share_name, // 分享标题
				desc: '我发现了一个很不错的商城，买家具有超大实惠！', // 分享描述
				link: self.$request.h5_share_url+'?page=index', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
				imgUrl: self.$request.h5_img_url+'/static/images/logo.png', // 分享图标
			}
			uni.setStorageSync('share_time_line',share_time_line);
			uni.setStorageSync('share_app_message',share_app_message);
			self.$request.wx_config()
			// #endif
			
		},
		onHide(){
			
		},
		onShareAppMessage(res) {
		    if (res.from === 'button') {
		      console.log(res.target)
		    }
		    return {
		      title: this.$request.share_title,
		      path: '/pages/index/index'
		    }
		  },
		methods: {
			goNote(){
				if(this.stauts_code == 40003){
					uni.navigateTo({
						url:'../login/login?page=main'
					})
				}else{
					uni.navigateTo({
					    url: '../my-note/my-note'
					});
				}
				
			},
			goGoods(){
				if(this.stauts_code == 40003){
					uni.navigateTo({
						url:'../login/login?page=main'
					})
				}else{
					uni.navigateTo({
					    url: '../my-goods/my-goods'
					});
				}
				
			},
			goFeedBack(){
				uni.navigateTo({
					url:'../feed-back/feed-back'
				})
			},
			goBonus(){
				if(this.stauts_code == 40003){
					uni.navigateTo({
						url:'../login/login?page=main'
					})
				}else{
					uni.navigateTo({
					    url: '../bonus/bonus'
					});
				}
				
			},
			goInvite(){
				if(this.stauts_code == 40003){
					uni.navigateTo({
						url:'../login/login?page=main'
					})
				}else{
					uni.navigateTo({
					    url: '../invite/invite'
					});
				}
				
			},
			goGold(){
				if(this.stauts_code == 40003){
					uni.navigateTo({
						url:'../login/login?page=main'
					})
				}else{
					uni.navigateTo({
					    url: '../gold/gold'
					});
				}
				
			},
			goOrder(id){
				if(this.stauts_code == 40003){
					uni.navigateTo({
						url:'../login/login?page=main'
					})
				}else{
					uni.navigateTo({
					    url: '../my-order/my-order?id='+id
					});
				}
				
			},
			chooseAddr(){
				var self = this;
				
				// #ifdef MP-WEIXIN
				uni.chooseAddress({
				  success(res) {
				    console.log(res.userName)
				    console.log(res.postalCode)
				    console.log(res.provinceName)
				    console.log(res.cityName)
				    console.log(res.countyName)
				    console.log(res.detailInfo)
				    console.log(res.nationalCode)
				    console.log(res.telNumber)
				  }
				})
				// #endif
				
				// #ifdef H5
				
				self.wx.openAddress({
				  success: function(res) {
					self.userName = res.userName;
					self.provinceName = res.provinceName;
					self.cityName = res.cityName;
					self.countyName = res.countryName;
					self.detailInfo = res.detailInfo;
					self.telNumber = res.telNumber;
					self.address_ok = true;
				  }
				});
				
				// #endif
			},
			log_out(){
				uni.removeStorageSync('user');
				uni.removeStorageSync('token');
				uni.reLaunch({
					url:"../index/index"
				})
			},
			goHelp(){
				uni.navigateTo({
				    url: '../help-center/help-center'
				});
			},
			goNew(){
				this.$request.request({
					url:'/user/info',
					success:function(res){
						if(res.code==200){
							uni.setStorageSync('notice',0);
							uni.navigateTo({
							    url: '../news/news'
							});
						}
						if(res.code==40003){
							uni.navigateTo({
								url:'../login/login?page=index'
							})
						}
					}
				});
			},
			goFeed(){
				uni.navigateTo({
				    url: '../feed-back/feed-back'
				});
			},
			goAboutUs(){
				uni.navigateTo({
				    url: '../about-us/about-us'
				});
			},
			goLuDan(){
				if(this.stauts_code == 40003){
					uni.navigateTo({
						url:'../login/login?page=main'
					})
				}else{
					uni.navigateTo({
					    url: '../../pagesA/record/record'
					});
				}
			},
			gobaobei(){
				var self = this;
				if(this.stauts_code == 40003){
					uni.navigateTo({
						url:'../login/login?page=main'
					})
				}else{
					if(self.user_info.is_receiver==1&&self.user_info.is_reportor==0){
						uni.navigateTo({
						    url: '../../pagesA/report-list/report-list?is=1&id='+self.user_info.id+'&identity=receiver'
						});
					}
					if(self.user_info.is_receiver==0&&self.user_info.is_reportor==1){
						uni.navigateTo({
						    url: '../../pagesA/report-list/report-list?is=0&id='+self.user_info.id+'&identity=reportor'
						});
					}
					if(self.user_info.is_receiver==1&&self.user_info.is_reportor==1){
						uni.navigateTo({
						    url: '../../pagesA/report-select/report-select?is_receiver='+self.user_info.is_receiver+'&is_reportor='+self.user_info.is_reportor+'&id='+self.user_info.id
						});
					}
					
				}
			}
		}
	}
</script>

<style>
@import url("main.css");
</style>
